<?php

//////////////////////////////////////////////////////
// GPAC Database is Copyright 2002 Colin Todd       //
// Written by Colin Todd - All rights reserved.     //
//                                                  //
// colintodd@myfastmail.com                         //
//////////////////////////////////////////////////////

$alphabet = @$_GET['alphabet'];

$result_Indv_count = mysql_query("SELECT count(*) as 'Num of Individuals' FROM ".$PACTS_cfg->individualtablename."",$PACTS_cfg->dblink);
$result_Fmly_count = mysql_query("SELECT count(*) as 'Num of Families' FROM $PACTS_cfg->familytablename",$PACTS_cfg->dblink);

$result_Indv_rolegendercount = mysql_query("SELECT ".$PACTS_cfg->gendertablename.".Description as Gender, ".$PACTS_cfg->individualtablename.".RoleTypeCode as Role, Count(".$PACTS_cfg->individualtablename.".GenderCode) AS Count FROM ".$PACTS_cfg->individualtablename." LEFT JOIN Gender ON ".$PACTS_cfg->individualtablename.".GenderCode = Gender.GenderCode GROUP BY ".$PACTS_cfg->individualtablename.".RoleTypeCode, Gender.Description;",$PACTS_cfg->dblink);
$result_Indv_gendercount = mysql_query("SELECT ".$PACTS_cfg->gendertablename.".Description, Count(".$PACTS_cfg->individualtablename.".GenderCode) AS Count FROM ".$PACTS_cfg->gendertablename." LEFT JOIN Individual ON Gender.GenderCode = ".$PACTS_cfg->individualtablename.".GenderCode GROUP BY Gender.Description;",$PACTS_cfg->dblink);
$result_Indv_gendercount_blank = mysql_query("SELECT Count(*) FROM ".$PACTS_cfg->individualtablename." WHERE (((".$PACTS_cfg->individualtablename.".GenderCode)=\"\")) OR (((".$PACTS_cfg->individualtablename.".GenderCode) Is Null));",$PACTS_cfg->dblink);
$result_Indv_Rolecount = mysql_query("SELECT ".$PACTS_cfg->roletypetablename.".Description, Count(".$PACTS_cfg->individualtablename.".RoleTypeCode) AS Count FROM ".$PACTS_cfg->individualtablename." RIGHT JOIN RoleType ON ".$PACTS_cfg->individualtablename.".RoleTypeCode = ".$PACTS_cfg->roletypetablename.".RoleTypeCode GROUP BY ".$PACTS_cfg->roletypetablename.".Description;",$PACTS_cfg->dblink);
$result_Indv_Rolecount_blank = mysql_query("SELECT Count(*) FROM ".$PACTS_cfg->individualtablename." WHERE (((".$PACTS_cfg->individualtablename.".RoleTypeCode)=\"\")) OR (((".$PACTS_cfg->individualtablename.".RoleTypeCode) Is Null));",$PACTS_cfg->dblink);



$result_Indv_Maritalcount_blank = mysql_query("SELECT Count(*) FROM Individual WHERE (((".$PACTS_cfg->individualtablename.".MaritalStatusCode)=\"\")) OR (((".$PACTS_cfg->individualtablename.".MaritalStatusCode) Is Null));",$PACTS_cfg->dblink);


//$result_Indv_Maritalcount = mysql_query("SELECT MaritalStatus.Description AS 'Marital Status', Count(".$PACTS_cfg->individualtablename.".MaritalStatusCode) AS Count FROM Individual LEFT JOIN MaritalStatus ON ".$PACTS_cfg->individualtablename.".MaritalStatusCode = MaritalStatus.MaritalStatusCode WHERE (((".$PACTS_cfg->individualtablename.".MaritalStatusCode) Is Null Or (".$PACTS_cfg->individualtablename.".MaritalStatusCode) Is Not Null)) GROUP BY ".$PACTS_cfg->individualtablename.".MaritalStatusCode, MaritalStatus.Description;");

$result_Indv_Maritalcount = mysql_query("SELECT MaritalStatus.Description, Count(".$PACTS_cfg->individualtablename.".MaritalStatusCode) AS Count FROM Individual RIGHT JOIN MaritalStatus ON ".$PACTS_cfg->individualtablename.".MaritalStatusCode = MaritalStatus.MaritalStatusCode GROUP BY MaritalStatus.Description;",$PACTS_cfg->dblink);



$result_Indv_agerange_blank = mysql_query("SELECT Count(*) FROM Individual WHERE (((".$PACTS_cfg->individualtablename.".AgeRange)=\"\")) OR (((".$PACTS_cfg->individualtablename.".AgeRange) Is Null));",$PACTS_cfg->dblink);

$result_Indv_agerange = mysql_query("SELECT AgeRange.Description, Count(".$PACTS_cfg->individualtablename.".AgeRange) AS Count FROM AgeRange LEFT  JOIN Individual ON AgeRange.AgeRange = ".$PACTS_cfg->individualtablename.".AgeRange GROUP BY AgeRange.Description ORDER BY OrderNum;",$PACTS_cfg->dblink);


$result_Fmly_Suburbcount = mysql_query("SELECT ResidentialSuburb, Count(ResidentialSuburb) AS Count FROM Family GROUP BY Family.ResidentialSuburb ORDER BY Count DESC LIMIT 0,10;",$PACTS_cfg->dblink);

$result_Fmly_Indvcount = mysql_query("SELECT Family.FamilyShortName, Count(".$PACTS_cfg->individualtablename.".FamilyId) AS Count FROM Family INNER JOIN Individual ON Family.FamilyId = ".$PACTS_cfg->individualtablename.".FamilyId GROUP BY Family.FamilyShortName, Family.FamilyId ORDER BY Count DESC LIMIT 0,10;",$PACTS_cfg->dblink);

$result_Indv_Schoolcount = mysql_query("SELECT ".$PACTS_cfg->individualtablename.".EducationalInstitutionName, Count(".$PACTS_cfg->individualtablename.".EducationalInstitutionName) AS Count FROM Family INNER JOIN Individual ON Family.FamilyId = ".$PACTS_cfg->individualtablename.".FamilyId GROUP BY ".$PACTS_cfg->individualtablename.".EducationalInstitutionName ORDER BY Count DESC LIMIT 0,10;",$PACTS_cfg->dblink);

$result_Fmly_IndvAvg = mysql_query("SELECT AVG(Count) as 'Average Individuals In Family' FROM (SELECT Count(".$PACTS_cfg->individualtablename.".FamilyId) as Count FROM Individual GROUP BY ".$PACTS_cfg->individualtablename.".FamilyId) t1;",$PACTS_cfg->dblink);


$result_Fmly_ChildrenAvg = mysql_query("SELECT AVG(Count) as 'Average Num Children In Family' FROM (SELECT Count(".$PACTS_cfg->individualtablename.".FamilyId) as Count FROM ".$PACTS_cfg->individualtablename." WHERE (((".$PACTS_cfg->individualtablename.".RoleTypeCode)='Child')) GROUP BY ".$PACTS_cfg->individualtablename.".FamilyId ) AS t1;",$PACTS_cfg->dblink);

//SELECT Count(".$PACTS_cfg->individualtablename.".FamilyId) AS [Count] FROM Individual WHERE (((".$PACTS_cfg->individualtablename.".RoleTypeCode)="Child")) GROUP BY ".$PACTS_cfg->individualtablename.".FamilyId;







//////////////

echo '<div id="page_header">'."\n";
echo '<ul>'."\n";
echo '<li class="titlename2">Statistics</li>'."\n";
echo '</ul>'."\n";
echo '</div>'."\n";

echo '<div id="details-section">'."\n";


echo '<div id="viewDetailsC1">'."\n";
echo '<ul>'."\n";
echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_count ,"Count of Individuals")."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Fmly_count  ,"Count of Families")."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Fmly_IndvAvg   ,"Average Size of Family")."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Fmly_ChildrenAvg ,"Average Children in Family" )."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_Rolecount,"Roles",FALSE,"",$result_Indv_Rolecount_blank )."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_gendercount,"Gender",FALSE,"",$result_Indv_gendercount_blank )."";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_Maritalcount,"Marital Status",FALSE,"",$result_Indv_Maritalcount_blank )."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_agerange ,"Age Ranges",FALSE,"",$result_Indv_agerange_blank)."\n";
echo '</li>';


echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Fmly_Suburbcount ,"Top 10 Suburbs")."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Fmly_Indvcount  ,"Top 10 Sized Families")."\n";
echo '</li>';

echo '<li class="colw33pc">';
echo $PACTS_cfg->getStatisticsTable($result_Indv_Schoolcount  ,"Top 10 Schools", TRUE)."\n";
echo '</li>';

//echo '<li class="colw50pc">';




echo '</ul>'."\n";

echo '</div>'."\n";
echo '</div>'."\n";




/*


/////////////












echo "<table border=0><tr>";
//echo $PACTS_cfg->getStatisticsTable($result_Indv_count ,"Count of Individuals")."<br />";
//echo $PACTS_cfg->getStatisticsTable($result_Fmly_count  ,"Count of Families")."\n";
echo $PACTS_cfg->getStatisticsTable($result_Fmly_IndvAvg   ,"Average Size of Family")."<br />";
echo "</tr></table>";

$PACTS_cfg->end_div_main();
*/
 ?>


